package com.salton123.soulove.sailfish.video.ui.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.salton123.soulove.api.RouterManager;
import com.salton123.soulove.app.R;
import com.salton123.soulove.sailfish.db.VideoItem;
import com.salton123.soulove.sailfish.video.SailfishManager;
import com.salton123.utils.ImageLoader;

import java.util.List;

import androidx.viewpager.widget.PagerAdapter;

/**
 * User: newSalton@outlook.com
 * Date: 2019/9/26 10:44
 * ModifyTime: 10:44
 * Description:
 */
public class UltraPagerAdapter extends PagerAdapter {
    List<VideoItem> mDatas;

    public UltraPagerAdapter(List<VideoItem> datas) {
        this.mDatas = datas;
    }

    @Override
    public int getCount() {
        return mDatas.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        ViewGroup viewGroup =
            (ViewGroup) LayoutInflater.from(container.getContext()).inflate(R.layout.banner_item, null);
        ImageView imageView = viewGroup.findViewById(R.id.bannerImage);
        imageView.setOnClickListener(view -> {
            SailfishManager.INSTANCE.setToPlayVideoList(mDatas);
            RouterManager.INSTANCE.videoPlay(container.getContext(), position);
        });
        ImageLoader.loadImage(imageView, mDatas.get(position).getFilePath());
        container.addView(viewGroup);
        return viewGroup;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        View view = (View) object;
        container.removeView(view);
    }
}